import scipy.io as sio
import h5py
import numpy as np
import matplotlib.pyplot as plt

yy1_path =  r"D:\\python_tests\\cc\\color_correction\\visualization\data\\yy_1.mat"
yy2_path =  r"D:\\python_tests\\cc\\color_correction\\visualization\data\\yy_2.mat"
yy3_path =  r"D:\\python_tests\\cc\\color_correction\\visualization\data\\yy_3.mat"
yy4_path =  r"D:\\python_tests\\cc\\color_correction\\visualization\data\\yy_4.mat"

with h5py.File(yy1_path,'r') as f:
    for key in f.keys():
        if key == 'cube':
            yy1_data = f[key][:]
            print("yy1.shape:" + str(yy1_data.shape))
            print("yy1.dtype:" + str(yy1_data.dtype))
    
with h5py.File(yy2_path,'r') as f:
    for key in f.keys():
        if key == 'cube':
            yy2_data = f[key][:]
            print("yy2.shape:" + str(yy2_data.shape))
            print("yy2.dtype:" + str(yy2_data.dtype))

with h5py.File(yy3_path,'r') as f:
    for key in f.keys():
        if key == 'cube':
            yy3_data = f[key][:]
            print("yy3.shape:" + str(yy3_data.shape))
            print("yy3.dtype:" + str(yy3_data.dtype))

with h5py.File(yy4_path,'r') as f:
    for key in f.keys():
        if key == 'cube':
            yy4_data = f[key][:]
            print("yy4.shape:" + str(yy4_data.shape))
            print("yy4.dtype:" + str(yy4_data.dtype))

def cal_patch_value(hsi_patch_data):
    bands = hsi_patch_data.shape[0]
    spec_value =[np.mean(hsi_patch_data[i,:,:]) for i in range(bands)]
    return spec_value

yy1_data_patch = yy1_data[:,1:137,1:147]
yy2_data_patch = yy2_data[:,1:137,1:147]
yy3_data_patch = yy3_data[:,1:137,1:147]
yy4_data_patch = yy4_data[:,1:137,1:147]

spec_yy1_value = cal_patch_value(yy1_data_patch)
spec_yy2_value = cal_patch_value(yy2_data_patch)
spec_yy3_value = cal_patch_value(yy3_data_patch)
spec_yy4_value = cal_patch_value(yy4_data_patch)

def draw_cur(wavelengths, spectrum_values, marker, linestyle, color, label):  
    plt.plot(wavelengths, spectrum_values, marker=marker, linestyle=linestyle, color=color, label=label)  

wavelengths_curve = [i for i in range(1,32)]

# 确保两个数组的长度相同  
assert len(wavelengths_curve) == len(spec_yy1_value),"wavelengths_curve数组和spec_yy1_value数组必须拥有相同长度" 

draw_cur(wavelengths_curve, spec_yy1_value, marker='s', linestyle='--', color='g', label='yy1')
draw_cur(wavelengths_curve, spec_yy2_value, marker='o', linestyle='--', color='r', label='yy2')
draw_cur(wavelengths_curve, spec_yy3_value, marker='^', linestyle='--', color='b', label='yy3')
draw_cur(wavelengths_curve, spec_yy4_value, marker='.', linestyle='--', color='y', label='yy4')

# 添加网格线  
plt.grid(True)
  
# 添加图例（如果需要）  
plt.legend()  
  
# 设置标题和坐标轴标签 
plt.title('Spectral WaveLength')  
plt.xlabel('Wavelength')  
plt.ylabel('Spectral Valua')

# 显示图形 
plt.show()